import { configureStore } from '@reduxjs/toolkit'

import { useSelector, TypedUseSelectorHook, useDispatch } from 'react-redux'

import counterReducer from './modules/counter'

const store = configureStore({
  reducer: {
    counter: counterReducer,
  },
})

type GetStateFnType = typeof store.getState
export type IRootState = ReturnType<GetStateFnType>
export type AppDispatch = typeof store.dispatch

export const useAppSelector: TypedUseSelectorHook<IRootState> = useSelector
export const useAppDispatch: () => AppDispatch = useDispatch

export default store
